package algebra.query.pd;

import java.util.HashSet;
import java.util.Set;

import option.QueryKeywords;

import utils.Display;
import utils.Util;

import entities.concept.Concept;
import entities.role.Role;

public class PdConcept extends ProjDesc {

	private final Concept cp;
	
	public PdConcept(Concept c){
		this.cp = c;
	}
	
	public Concept getConcept(){
		return this.cp;
	}

	@Override
	public boolean projectOnSomeFeature() {
		return false;
	}

	@Override
	public Set<Role> extractFeatures() {
		Set<Role> fs = new HashSet<Role>();
		fs.addAll(cp.extractFeatures());
		return fs;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((cp == null) ? 0 : cp.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof PdConcept))
			return false;
		PdConcept other = (PdConcept) obj;
		if (cp == null) {
			if (other.cp != null)
				return false;
		} else if (!cp.equals(other.cp))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return this.cp + Display.QUERYSYMBOL;
	}

	@Override
	public String toSerializedString() {
		return "(" + QueryKeywords.PD_CONCEPT + " "
				+ this.cp.toSerializedString() + ")";
	}

	@Override
	public boolean moreSpecificThan(ProjDesc that) {
		if(that instanceof PdConcept){
			return Util.subsumes(this.cp, ((PdConcept)that).cp, null);
		}
		return false;
	}

	@Override
	public boolean hasConjunctiveFeature() {
		return false;
	}
	
	
}
